import os
import datetime

class VersionInfo:
    def __init__(self, version):
        ids = version.split('.')
        self.MainVer = ids[0]
        self.SubVer = ids[1]
        self.PubVer = ids[2]
        self.BuildVer = ids[3]
        nowtime = datetime.datetime.now()
        self.UpdateDate = "%04d%02d%02d"%(nowtime.year, nowtime.month, nowtime.day)



def WriteVersionToFile(filepath:str, versionId:str):
    versionInfo = VersionInfo(versionId)

    with open(filepath, 'w') as versionFile:
        versionFile.write("#pragma once\n\n")
        versionFile.write("#define MainVer {}\n".format(versionInfo.MainVer))
        versionFile.write("#define SubVer {}\n".format(versionInfo.SubVer))
        versionFile.write("#define PubVer {}\n".format(versionInfo.PubVer))
        versionFile.write("#define BuildVer {}\n".format(versionInfo.BuildVer))
        versionFile.write("#define UpdateDate {}\n".format(versionInfo.UpdateDate))

if __name__ == '__main__':
    WriteVersionToFile('ver.h', '6.1.2.3')

    
